package com.kbtd.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RedissonConfig {
    @Value("${spring.redis.host}")
    private String redisHost;
    @Value("${spring.redis.port}")
    private Integer redisPort;

    private static final String REDIS_ADDRESS_PREFIX = "redis://";

    @Bean
    public RedissonClient redissonClient(){
        //配置
        Config config = new Config();
        String address = REDIS_ADDRESS_PREFIX + redisHost + ":" + redisPort;
        config.useSingleServer().setAddress(address);
        //创建redissonClient 对象
        return Redisson.create(config);
    }
}
